#### This script will match two very large microclimate datasets by site, date, and time
#### Then need to interrogate for differences in time/magnitude of max temps between ambient and under log data loggers
#### Set up a directory

raw.dir = '/home1/99/jc152199/underlogdownscale/rawmicroclimatedata/'

### Read in underlog rawdata

ulraw = read.csv(paste(raw.dir,'underlograwdata.csv',sep=''),header=T)

### Remove any NA's from ultemp

ulraw = ulraw[which(is.na(ulraw$ultemp)==F),]


### Aggregate to produce daily max and daily min for ultemp

ulag = aggregate(ulraw[,11], by=list(site=ulraw$site,date=ulraw$date), FUN=max)
ulag2 = aggregate(ulraw[,11], by=list(site=ulraw$site,date=ulraw$date), FUN=min)

### Change some names

names(ulag)[3] = 'ulmax'

### Add data to ulag

ulag$ulmin = ulag2[,3]

#### Write out ulag

write.csv(ulag, file=paste(raw.dir,'ulagWITHOUTEmpiricalAirTemp.csv',sep=''), row.names=F)


